<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="学校名称" prop="content">
        <el-input
          v-model="queryParams.content"
          placeholder="请输入学校名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="detailList" @selection-change="handleSelectionChange">
      <el-table-column label="学校" align="center" prop="college_name" />
      <el-table-column label="试卷数量" align="center" prop="parpercount" />
      <el-table-column label="参考人数" align="center" prop="totaltest" />
      <el-table-column label="总人数" align="center" prop="sumstudent" />
      <el-table-column label="合格率" align="center" prop="hgrate" />
      <el-table-column label="参考率" align="center" prop="ckrate" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
          >查看详情</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

     <!-- 添加或修改答题详情对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1200px"  append-to-body>
      <el-form ref="form" :model="infoQueryParams" :rules="rules" :inline="true" label-width="80px">
        <el-form-item label="试卷名称" prop="content">
          <el-input v-model="infoQueryParams.content" placeholder="请输入试卷名称" />
        </el-form-item>
         <el-form-item>
          <el-button type="cyan" icon="el-icon-search" size="mini" @click="infoHandleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetInfoQuery">重置</el-button>
        </el-form-item>
      </el-form>
    <el-table v-loading="loading" :data="infoDetailList"  height="530px">
      <el-table-column label="试卷名称" align="center" prop="name" />
      <el-table-column label="参考人数" align="center" prop="tester_count" />
      <el-table-column label="总人数" align="center" prop="count" />
      <el-table-column label="合格率" align="center" prop="gfl" />
      <el-table-column label="参考率" align="center" prop="ckl" />
    </el-table>
      <pagination
      v-show="infoTotal>0"
      :total="infoTotal"
      :page.sync="infoQueryParams.pageNum"
      :limit.sync="infoQueryParams.pageSize"
      @pagination="getInfoList"
    />
    </el-dialog>
  </div>
</template>

<script>
import { listInfo, listDetail, getDetail, delDetail, addDetail, updateDetail, exportDetail } from "@/api/system/detail";

export default {
  name: "Detail",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      id: 0,
      ids:[],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 答题详情表格数据
      detailList: [],
      // 弹出层标题
      title: "查看学校试卷详情",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        collegePaperAnswerId: null,
        questionStoreId: null,
        content: null,
        standartAnswer: null,
        totalScore: null,
        score: null,
        answerResult: null
      },
      // 表单参数
      form: {},
      rules: {
      },
        // 详情总条数
      infoTotal: 0,
      // 详情表格数据
      infoDetailList: [],
      // 查询参数
      infoQueryParams: {
        pageNum: 1,
        pageSize: 10,
        content: null,
        collegePaperAnswerId: null,
      },
    };

  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询学校试卷列表 */
    getList() {
      this.loading = true;
      listDetail(this.queryParams).then(response => {
        this.detailList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

        /** 查询学校试卷列表搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },

    /** 查询学校试卷列表重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },

/** 查询学校试卷列表详情 */
    getInfoList() {
      this.loading = true;
      this.infoQueryParams.collegePaperAnswerId=this.id;
      listInfo(this.infoQueryParams).then(response => {
        this.infoDetailList = response.rows;
        this.infoTotal = response.total;
        this.open=true;
        this.title = "查看学校考试详情";
        this.loading = false;
      });
    },

    // 取消按钮
    cancel() {
      this.open = false;
      this.id=0;
      this.reset();
    },
    // 表单重置
    reset() {
      this.infoQueryParams = {
        content: null,
      };
      this.resetForm("infoQueryParams");
    },

/** 查询学校试卷列表详情搜索按钮 */
    infoHandleQuery() {
      this.infoQueryParams.pageNum = 1;
      this.getInfoList();
    },
       /** 重置按钮操作 */
    resetInfoQuery() {
       this.infoQueryParams = {
        content: null,
      };
      this.resetForm("infoQueryForm");
      this.getInfoList();
    },


    /** 查看详情按钮操作 */
    handleUpdate(row) {
      let that = this;
      that.reset();
      that.id = row.college_id;
      that.getInfoList();
     
    },

        // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },

  }
};
</script>
